# 给定一个列表, 根据`grade`来排序
classes = [
    {"name": "n_1", "age": 24, "grade": "A"},
    {"name": "n_2", "age": 23, "grade": "B"},
    {"name": "n_3", "age": 28, "grade": "A"},
    {"name": "n_4", "age": 24, "grade": "A"},
    {"name": "n_5", "age": 25, "grade": "C"},
    {"name": "n_6", "age": 21, "grade": "D"},
    {"name": "n_7", "age": 27, "grade": "A"},
]
classes.sort(key=lambda x: x["grade"])
print(classes)

# 通过`filter`语句来筛选出`Grade`为`A`的同学
result = filter(lambda x: True if x["grade"] == "A" else False, classes)
print(list(result))


# 通过`map`函数将上述同学的`age` + 1(对原数据结构有影响, 尽量不要用lambda)
def my_add(x):
    return x["age"] + 1


m = map(my_add, classes)
print(list(m))
print(classes)  # 不变


# 使用递归函数重构斐波那契函数
def my_Fib(n):
    if n == 0:
        return 0
    elif n == 1:
        return 1
    else:
        return my_Fib(n - 1) + my_Fib(n - 2)


if __name__ == "__main__":
    print(my_Fib(10))
